package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import com.sky.result.PageResult;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

        @Insert("insert into dish(name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) " +
                "values (#{name}, #{categoryId}, #{price},#{image},#{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
        void insert(Dish dish);

        Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

        @Select("select * from dish where id = #{id}")
        Dish getByIdWithFlavor(Long id);

        //    @AutoFill(OperationType.UPDATE)
        void update(Dish dish);

        @Select("select * from dish where id = #{id}")
        Dish getById(Long id);

        @Delete("delete from dish where id = #{id}")
        void delete(Long id);

        @Select("select * from dish where category_id = #{categoryId} and status = 1")
        List<Dish> list(Long categoryId);

        /**
         * 根据套餐id查询菜品
         * @param id
         * @return
         */
        List<Dish> getBySetmealId(Long id);

        @Select("select count(1) from dish where category_id = #{id}")
        Integer countByCategoryId(Long id);
}